﻿Imports DevExpress.XtraEditors

Public Class frmDoimatkhau

    Private Function Doimatkhau() As Boolean
        Dim myUser As New User
        Dim myUserF As New UserF

        Return myUserF.ChangePassword(Project_UserName, Me.txtNewPassword.Text.Trim)
    End Function

    Private Sub btnGhi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGhi.Click
        Dim myUserF As New UserF
        'kiem tra mat khau hien tai
        If myUserF.ExistsAccount(Project_UserName, Me.txtOldPassword.EditValue) Then
            'kiem tra mat khau xac nhan lai
            If Me.txtNewPassword.EditValue = Me.txtConfirmPassword.Text.Trim Then
                If Doimatkhau() Then
                    XtraMessageBox.Show("Đổi mật khẩu thành công", "Quản lý tiền lương", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Me.btnThoat.Focus()
                Else
                    XtraMessageBox.Show("Đổi mật khẩu không thành công", "Quản lý tiền lương", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Else
                XtraMessageBox.Show("Xin xác nhận lại mật khẩu", "Quản lý tiền lương", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.txtConfirmPassword.Focus()
            End If
        Else
            XtraMessageBox.Show("Mật khẩu hiện tại không đúng", "Quản lý tiền lương", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.txtOldPassword.Focus()
        End If
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub txtOldPassword_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtOldPassword.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.txtNewPassword.Focus()
        End If

    End Sub

    Private Sub txtNewPassword_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNewPassword.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.txtConfirmPassword.Focus()
        End If
    End Sub

    Private Sub txtConfirmPassword_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtConfirmPassword.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.btnGhi.Focus()
        End If
    End Sub

End Class